home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug232 / form.st < prev    next >
Text File  |  1987-06-17  |  3KB  |  117 lines

  1. Class Form
  2. | text |
  3. [
  4.     new
  5.         text <- Array new: 0
  6. |
  7.     clipFrom: upperLeft to: lowerRight    
  8.         | newForm newRow rsize left top rText |
  9.  
  10.         left <- upperLeft y - 1.  " left hand side"
  11.         top <- upperLeft x - 1.
  12.         rsize <- lowerRight y - left.
  13.         newForm <- Form new.
  14.         (upperLeft x to: lowerRight x) do: [:i |
  15.             newRow <- String new: rsize.
  16.             rText <- self row: i.
  17.             (1 to: rsize) do: [:j |
  18.                 newRow at: j
  19.                     put: (rText at: (left + j)
  20.                         ifAbsent: [$ ])].
  21.             newForm row: (i - top) put: newRow ].
  22.         ^ newForm
  23. |
  24.     columns
  25.         ^ text inject: 0 into: [:x :y | x max: y size ]
  26. |
  27.     display
  28.         smalltalk clearScreen.
  29.         self printAt: 1 @ 1.
  30.         '  ' printAt: 20 @ 0
  31. |
  32.     eraseAt: aPoint        | location |
  33.         location <- aPoint copy.
  34.         text do: [:x | (String new: (x size)) printAt: location.
  35.                 location x: (location x + 1) ]
  36. |
  37.     extent
  38.         ^ self rows @ self columns
  39. |
  40.     first
  41.         ^ text first
  42. |
  43.     next
  44.         ^ text next
  45. |
  46.     overLayForm: sourceForm at: startingPoint
  47.         | newRowNumber rowText left rowSize |
  48.  
  49.         newRowNumber <- startingPoint x.
  50.         left <- startingPoint y - 1.
  51.         sourceForm do: [:sourceRow |
  52.             rowText <- self row: newRowNumber.
  53.             rowSize <- sourceRow size.
  54.             rowText <- rowText padTo: (left + rowSize).
  55.             (1 to: rowSize) do: [:i |
  56.                 ((sourceRow at: i) ~= $ )
  57.                 ifTrue: [ rowText at: (left + i)
  58.                         put: (sourceRow at: i)]].
  59.             self row: newRowNumber put: rowText.
  60.             newRowNumber <- newRowNumber + 1]
  61. |
  62.     placeForm: sourceForm at: startingPoint
  63.         | newRowNumber rowText left rowSize |
  64.  
  65.         newRowNumber <- startingPoint x.
  66.         left <- startingPoint y - 1.
  67.         sourceForm do: [:sourceRow |
  68.             rowText <- self row: newRowNumber.
  69.             rowSize <- sourceRow size.
  70.             rowText <- rowText padTo: (left + rowSize).
  71.             (1 to: rowSize) do: [:i |
  72.                 rowText at: (left + i)
  73.                     put: (sourceRow at: i)].
  74.             self row: newRowNumber put: rowText.
  75.             newRowNumber <- newRowNumber + 1]
  76. |
  77.     reversed        | newForm columns newRow |
  78.         columns <- self columns.
  79.         newForm <- Form new.
  80.         (1 to: self rows) do: [:i |
  81.             newRow <- text at: i.
  82.             newRow <- newRow ,
  83.                 (String new: (columns - newRow size)).
  84.             newForm row: i put: newRow reversed ].
  85.         ^ newForm
  86.  
  87. |
  88.     rotated            | newForm rows newRow |
  89.         rows <- self rows.
  90.         newForm <- Form new.
  91.         (1 to: self columns) do: [:i |
  92.             newRow <- String new: rows.
  93.             (1 to: rows) do: [:j |
  94.                 newRow at: ((rows - j) + 1)
  95.                     put: ((text at: j)
  96.                         at: i ifAbsent: [$ ])].
  97.             newForm row: i put: newRow ].
  98.         ^ newForm
  99. |
  100.     row: index
  101.         ^ text at: index ifAbsent: ['']
  102. |
  103.     row: index put: aString
  104.         (index > text size)
  105.             ifTrue: [ [text size < index] whileTrue:
  106.                     [text <- text grow: ''] ].
  107.         text at: index put: aString
  108. |
  109.     rows
  110.         ^ text size
  111. |
  112.     printAt: aPoint        | location |
  113.         location <- aPoint copy.
  114.         text do: [:x | x printAt: location.
  115.                 location x: (location x + 1) ]
  116. ]
  117.